package club.banyuan.SpringBootHrms.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.catalina.connector.Request;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
public class LoginController {

    @GetMapping("/")
    public String index(){
        return "login.html";
    }

    @PostMapping("/admin/login")
    public String login(String username, String password) {
        if (verify(username,password)) {
            // 重定向
            // 不加redirect 就相当于转发
            return "redirect:/home_page.html?id=" + 1;
        }else {
            return "redirect:/login.html";
        }
    }

    private boolean verify(String username, String password) {
        return "admin".equals(username) && "123456".equals(password);
    }
}
